<?php
	include_once '../models/Model.php';
	/*$userID=$_COOKIE['userID'];
	$month=$_GET['month'];*/
	session_start();
    if(!isset($_GET['userid']))
	 $userId=$_SESSION['userId'];
	else 
	 $userId=$_GET['userid']; 
    //get booked room
    //echo $userId;die;
	$month=date('Y-m');
	//echo $month.';'.$userId;
	$model=new Model();
	$order=$model->searchOrderByUserId($month,$userId);
	// no order
	$now=time();
	if(count($order)>0)
	{	//include_once 'applications/view/viewOrdered.php';
		foreach($order as $item)
		{
			$roomId=$item->getRoomId();
			$room=$model->getRoomById($roomId);
			$roomName=$room->getRoomName();
			$orderStartTime=strtotime($item->getOrderStartTime());
			//echo $item->getOrderStatus();
			$orderStatus=$item->getOrderStatus();
			if(($now+2*60*60)<=$orderStartTime && $orderStatus==1) 
				$flag=0;
			else if($orderStatus==2)
			 	$flag=1;
			else  
		     	$flag=2; 
			//echo $flag;die;
			$output[]=array('roomName'=>$roomName,'time'=>$item->getOrderStartTime().'->'.$item->getOrderEndTime(),'flag'=>$flag,'orderId'=>$item->getOrderId());			
		}		
	}
	else
		$output='none';
	if(!isset($_GET['userid']))	
		include_once '../view/user/view_room.php';
	else
		include_once '../view/manager/view_booked_order.php';		
?>